package com.inspur.demo.controller;

import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 生产者控制层
 */
@RestController
@RequestMapping("/producer")
public class ProducerController {

    private HttpServletRequest request;

    @RequestMapping("/test/{name}")
    public String test(@PathVariable String name) {
        String contextPath = this.request.getRequestURL().toString();
        return "Hello, " + name + ", you are from \"" + contextPath + "\"!";
    }

    @ModelAttribute
    public void setReqAndRes(HttpServletRequest request, HttpServletResponse response) {
        this.request = request;
    }
}
